﻿@using DualControl.CommonServices
@using DualControl.HazardSources.Dtos
@using DualControl.Common

@model Abp.Application.Services.Dto.ListResultDto<HazardSourceListDto>
@using X.PagedList.Mvc.Core; @*import this so we get our HTML Helper*@
@using X.PagedList; @*import this so we can cast our list to IPagedList (only necessary because ViewBag is dynamic)*@

@inject ICommonService CommonService

@{
    ViewData["Title"] = "危险点管理";
}

@section scripts
    {
    <environment names="Development">
        <script src="~/view-resources/Views/RiskPoints/Index.js" asp-append-version="true"></script>
    </environment>
    <environment names="Staging,Production">
        <script src="~/view-resources/Views/RiskPoints/Index.min.js" asp-append-version="true"></script>
    </environment>
}
<div class="row clearfix">
    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
        <div class="card">
            <div class="header">
                <h2>
                    @L("RiskPoint")
                </h2>
                <ul class="header-dropdown m-r--5">
                    <li class="dropdown">
                        <a href="javascript:void(0);" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                            <i class="material-icons">more_vert</i>
                        </a>
                        <ul class="dropdown-menu pull-right">
                            <li><a id="RefreshButton" href="javascript:void(0);" class="waves-effect waves-block"><i class="material-icons">refresh</i>@L("Refresh")</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
            <div class="body table-responsive">
                <table class="table">
                    <thead>
                        <tr>
                            <th>编码</th>
                            <th>责任部门</th>
                            <th>区域/工段</th>
                            <th>风险点名称</th>
                            <th>位置</th>                          
                            <th>作业目的</th>
                            <th>事故类型</th>
                            <th>影响后果</th>
                            <th>备注</th>
                            <th>@L("Actions")</th>
                        </tr>
                    </thead>
                    <tbody>
                        
                        @foreach (var riskPoints in ViewBag.PageOfRiskPointListDto)
                        {
                        <tr>
                            <td>@riskPoints.Code</td>
                            <td>@CommonService.GetOrganizationUnits().SingleOrDefault(c => c.Key == riskPoints.OrganizationUnitId).Value </td>
                            <td>@riskPoints.AreaOrSection</td>
                            <td>@riskPoints.Name</td>
                            <td>@riskPoints.Location</td>                           
                            <td>@riskPoints.OperationPurpose</td>
                            <td>
                             @{
                                 string space = " ";
                                 if (riskPoints.AccidentTypesForView != null)
                                 {
                                     foreach (var accident in riskPoints.AccidentTypesForView)
                                     {
                                         @accident
                                         @space
                                      }
                                 }
                                 }
                            </td>
                            <td>@riskPoints.AccidentConsequences</td>
                            <td>@riskPoints.Note</td>
                            <td class="dropdown">
                                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
                                    <i class="material-icons">menu</i>
                                </a>
                                <ul class="dropdown-menu pull-right">
                                    <li><a href="#" class="waves-effect waves-block edit-riskpoint" data-riskpoint-id="@riskPoints.Id" data-toggle="modal" data-target="#RiskPointEditModal"><i class="material-icons">edit</i>@L("Edit")</a></li>
                                    <li><a href="#" class="waves-effect waves-block delete-riskpoint" data-riskpoint-id="@riskPoints.Id" data-riskpoint-name="@riskPoints.Name"><i class="material-icons">delete_sweep</i>@L("Delete")</a></li>
                                </ul>
                            </td>
                        </tr>
                        }
                    </tbody>
                </table>
                <button type="button" class="btn btn-primary btn-circle waves-effect waves-circle waves-float pull-right" data-toggle="modal" data-target="#RiskPointCreateModal">
                    <i class="material-icons">add</i>
                </button>
            </div>
        </div>
    </div>
</div>

@Html.PagedListPager((IPagedList)ViewBag.PageOfRiskPointListDto, page => Url.Action("Index", new { page }))

<div class="modal fade" id="RiskPointCreateModal" tabindex="-1" role="dialog" aria-labelledby="HazardSourceCreateModalLabel" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">
                    <span>新增风险点</span>
                </h4>
            </div>
            <div class="modal-body">
                <form name="hazardSourceCreateForm" role="form" novalidate class="form-validation">
                    <ul class="nav nav-tabs tab-nav-right" role="tablist">
                        <li role="presentation" class="active"><a href="#create-org-details" data-toggle="tab">基础信息</a></li>
                        <li role="presentation"><a href="#create-accidenttype-list" data-toggle="tab">风险点诱发事故类型</a></li>
                    </ul>
                    <div class="tab-content">
                        <div role="tabpanel" class="tab-pane animated fadeIn active" id="create-org-details">
                            <div class="row clearfix" style="margin-top:10px;">
                                <div class="col-sm-6">
                                    <div class="form-group form-float">
                                        <label class="form-label">请输入风险点编号</label>
                                        <input class="form-control" type="text" name="Code" required minlength="3" placeholder="请输入风险点编号">
                                    </div>
                                </div>
                                <div class="col-sm-6">
                                    <div class="form-group form-float">
                                        <label class="form-label">请选择责任部门</label>
                                        @Html.DropDownList("OrganizationUnitId",
CommonService.GetOrganizationUnits().Select(c =>
    new SelectListItem() { Text = c.Value.ToString(), Value = c.Key.ToString() }), "==请选择责任部门==", new { @class = "dropdownlist" })
                                    </div>
                                </div>

                            </div>

                            <div class="row clearfix" style="margin-top:10px;">
                                <div class="col-sm-6">
                                    <div class="form-group form-float">
                                        <label class="form-label">请输入区域工段</label>
                                        <input class="form-control" type="text" name="AreaOrSection" placeholder="请输入区域工段" required minlength="3">
                                    </div>
                                </div>

                                <div class="col-sm-6">
                                    <div class="form-group form-float">
                                        <label class="form-label">请输入风险点名称</label>
                                        <input class="form-control" type="text" name="Name" placeholder="请输入风险点名称" required minlength="3">

                                    </div>
                                </div>

                            </div>

                            <div class="row clearfix" style="margin-top:10px;">
                                <div class="col-sm-6">
                                    <div class="form-group form-float">
                                        <label class="form-label">请输入风险源位置</label>
                                        <input class="form-control" type="text" name="Location" placeholder="请输入风险源位置" required minlength="3">
                                    </div>
                                </div>
                                <div class="col-sm-6">
                                    <div class="form-group form-float">
                                        <label class="form-label">请输入作业目的</label>
                                        <input class="form-control" type="text" name="OperationPurpose" placeholder="请输入作业目的" required minlength="3">
                                    </div>
                                </div>
                            </div>
                            <div class="row clearfix" style="margin-top:10px;">
                                <div class="col-sm-6">
                                    <div class="form-group form-float">
                                        <label class="form-label">请输入风险源事故影响</label>

                                        <input class="form-control" type="text" name="AccidentConsequences" placeholder="请输入风险源事故影响" required minlength="3">
                                    </div>
                                </div>

                                <div class="col-sm-6">
                                    <div class="form-group form-float">
                                        <label class="form-label">请输入备注</label>
                                        <input class="form-control" type="text" name="Note" placeholder="请输入备注" required minlength="3">
                                    </div>
                                </div>
                            </div>                           
                        </div>

                        <div role="tabpanel" class="tab-pane animated fadeIn" id="create-accidenttype-list">                          

                            <div class="row">
                                <div class="col-sm-12 ">
                                    @foreach (var accident in CommonService.AccidentTypes())
                                    {
                                        <div class="col-sm-6">
                                            <input type="checkbox" name="accidentlist" value="@accident.Key" title="@accident.Value" class="filled-in form-simulation" id="role-@accident.Key" />
                                            <label for="role-@accident.Key" title="@accident.Value">@accident.Value</label>
                                        </div>
                                    }
                                </div>
                            </div>

                        </div>
                        </div>
                        <div class="modal-footer">
              <button type="button" class="btn btn-default waves-effect" data-dismiss="modal">@L("Cancel")</button>
               <button type="submit" class="btn btn-primary waves-effect">@L("Save")</button>
           </div>
</form>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="RiskPointEditModal" tabindex="-1" role="dialog" aria-labelledby="HazardSourceEditModalLabel" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">

        </div>
    </div>

</div>
